package com.luckzj.sec.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;

/**
 * Read Bridge Config from config files
 */
public class BridgeConfigReader {
    /**
     * Read Bridge Config from config files
     * Default BridgeConfigReader will try to read config files from different sources.
     * 1. Use etc/config.json
     * @return
     */
    public BridgeConfig[] readConfigs() {
        String filePath = "etc/config.json";

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Config config = objectMapper.readValue(new File(filePath), Config.class);
            return config.getBridgeConfigs();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }


    public static class Config {
        @JsonProperty("bridges")
        private BridgeConfig[] bridgeConfigs;

        public BridgeConfig[] getBridgeConfigs() {
            return bridgeConfigs;
        }

        public void setBridgeConfigs(BridgeConfig[] bridgeConfigs) {
            this.bridgeConfigs = bridgeConfigs;
        }
    }
}
